package com.dianganjiao.lib.util

import java.text.SimpleDateFormat
import java.util.*

/**
 * create file time : 2021/3/8
 * create user : wxl
 * subscribe :
 */
class DateUtils {
    companion object {
        val HMS = SimpleDateFormat("HH:mm:ss")
        val YMD = SimpleDateFormat("yyyy:MM:dd")
        val YMDHMS = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        val YMDHM = SimpleDateFormat("yyyy-MM-dd HH:mm")
        val Y_M_D = SimpleDateFormat("yyyy-MM-dd")
        val Y_M = SimpleDateFormat("yyyy-MM")
        val D = SimpleDateFormat("dd")
        val M = SimpleDateFormat("MM")
        val Y = SimpleDateFormat("yyyy")
        val YMDH = SimpleDateFormat("yyyy-MM-dd HH")

        fun getYTime(year:String):Date{
            return Y.parse(year)
        }

        fun getYMTime(ym:String):Date{
            return Y_M.parse(ym)
        }

        fun getYMDTime(ym:String):Date{
            return Y_M_D.parse(ym)
        }

        fun getY_M_D():String{
            return Y_M_D.format(Date())
        }

        fun getYMDHMTime(ym:String):Date{
            return YMDHM.parse(ym)
        }

        fun getYMDHTime(ym:String):Date{
            return YMDH.parse(ym)
        }

        fun getHMS(): String {
            return HMS.format(Date())
        }

        fun getYMDHMS(): String {
            return YMDHMS.format(Date())
        }

        fun getYMDHM(): String {
            return YMDHM.format(Date())
        }

        fun getYMDHM(time:Long): String {
            return YMDHM.format(Date(time))
        }

        fun getYMDY(time:String): Int {
            return time.split("-")[0].toInt()
        }

        fun getYMDM(time:String): Int {
            return time.split("-")[1].toInt()
        }

        fun getYMDD(time:String): Int {
            return time.split("-")[2].toInt()
        }

        fun getYMDH(time:String): Int {
            return time.split(" ")[1].toInt()
        }

        fun getYMDHD(time:String): Int {
            return time.split("-")[2].split(" ")[0].toInt()
        }

        fun getYMDH():String{
            return YMDH.format(Date())
        }

        fun getYMD(): String {
            return YMD.format(Date())
        }

        fun getYMD(time:Long): String {
            return YMD.format(Date(time))
        }

        fun getYMDHMY(time:String):Int{
            val split = time.split(" ")
            val split1 = split[0].split("-")
            return split1[0].toInt()
        }

        fun getYMDHMM(time:String):Int{
            val split = time.split(" ")
            val split1 = split[0].split("-")
            return split1[1].toInt()
        }

        fun getYMDHMD(time:String):Int{
            val split = time.split(" ")
            val split1 = split[0].split("-")
            return split1[2].toInt()
        }

        fun getYMDHMH(time:String):Int{
            val split = time.split(" ")
            val split1 = split[1].split(":")
            return split1[0].toInt()
        }

        fun getYMDHMm(time:String):Int{
            val split = time.split(" ")
            val split1 = split[1].split(":")
            return split1[1].toInt()
        }

        fun getY_M_D(time:Long): String {
            return Y_M_D.format(Date(time))
        }

        fun getY_M(ydmdate:String): String {
            val date = Y_M_D.parse(ydmdate)
            return Y_M.format(date)
        }

        fun getYM(): String {
            return Y_M.format(Date())
        }

        fun getD(ydmdate: String):String{
            val date = Y_M_D.parse(ydmdate)
            val format = D.format(date)
            if(format.startsWith("0")){
               return format.replace("0","")
            }
            return format
        }

        fun getZeroD(ydmdate: String):String{
            val date = Y_M_D.parse(ydmdate)
            return D.format(date)
        }

        fun getY(ydmdate: String):String{
            val date = Y_M_D.parse(ydmdate)
            return Y.format(date)
        }

        fun getM(ydmdate: String):String{
            val date = Y_M_D.parse(ydmdate)
            return M.format(date)
        }

        fun getYMDWeek() : String{
            val calendar = Calendar.getInstance()
            calendar.setTimeZone(TimeZone.getTimeZone("GMT+8:00"))
            val mYear = calendar.get(Calendar.YEAR) // 获取当前年份
            val mMonth = calendar.get(Calendar.MONTH) + 1// 获取当前月份
            val mDay = calendar.get(Calendar.DAY_OF_MONTH)// 获取当前月份的日期号码
            var mWay : String = calendar.get(Calendar.DAY_OF_WEEK).toString()
            when {
                "1".equals(mWay) -> {
                    mWay ="天"
                }
                "2".equals(mWay) -> {
                    mWay ="一"
                }
                "3".equals(mWay) -> {
                    mWay ="二"
                }
                "4".equals(mWay) -> {
                    mWay ="三"
                }
                "5".equals(mWay) -> {
                    mWay ="四"
                }
                "6".equals(mWay) -> {
                    mWay ="五"
                }
                "7".equals(mWay) -> {
                    mWay ="六"
                }
            }
            return "$mYear 年 $mMonth 月 $mDay 日  星期 $mWay"
        }
    }
}